angular.module('pa.fitler', [])
.filter('ipfilter', function(){
  return function(input,matcher) {
    if(!!input && !! matcher){
      var field = matcher.f;
      var netcpr = [];
      var newArr = [];
      angular.forEach(matcher.m,function(v,i){
        if(!!v){
          if(i==3){
            netcpr.push(v+'[0-9]*');            
          }else{
            netcpr.push(v);            
          }

        }else{
          netcpr.push("[0-9]{1,3}");
        }
      });
      var reg = new RegExp('^'+netcpr.join('\.')+'$');
      if(netcpr.length>0){
        angular.forEach(input, function(v,k){
          if(reg.test(v[field].trim())){
            newArr.push(v);
          }
        });
        return newArr;
      }else{
        return input;
      }
    }

    // return [input[0],input[1]];

    
  };
})
.filter('portFilter', function(){
  return function(input,matcher) {

    if(!!input && !! matcher){
      var field = matcher.f;
      var mv = matcher.m;
      var arr = [];
      if(!mv || mv == 'all'){
        return input
      }else{
        angular.forEach(input, function(v,k){
          if(mv == v[field].trim()){
            arr.push(v);
          }
        });
        return arr;        
      }
    }
  };
});